// $("#joinTime").datepicker({
//     format: 'yyyy-mm-dd'
// });

$CertusJsonAjax.ajax("queryYGRZProcessTrace", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.processCCBXTrace = res.data;
})

$("#joinTime").datetimepicker({
    format: 'YYYY-MM-DD',
    locale: moment.locale('zh-cn')
}).on('dp.change', function (e) {
    var result = new moment(e.date).format('YYYY-MM-DD');
    if (result && !angular.isUndefined(result)) {
        $$scope.rzlcStepEntity.baseUser.enrollTime = result;
    }
});

$$scope.getBelongCompanyName = function(companyCode){
    if(companyCode == "STSJT"){
        return "赛特斯集团";
    }else if(companyCode == "STSGD"){
        return "赛特斯广东";
    }else if(companyCode == "HFKJ"){
        return "浩方科技";
    }else if(companyCode == "HFXX"){
        return "浩方信息";
    }else if(companyCode == "STSBJ"){
        return "赛特斯北京";
    }else if(companyCode == "STSNJ"){
        return "赛特斯南京";
    }else if(companyCode == "STSSH"){
        return "赛特斯上海";
    }
}
//查询 基本 数据
$CertusJsonAjax.ajax("baseUserByProcessId", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {

    if (res.data) {
        $$scope.rzlcStepEntity = res.data;

        $$scope.rzlcStepEntity.baseUser.departmentUser.companyName = $$scope.getBelongCompanyName($$scope.rzlcStepEntity.baseUser.belongCompanyCode);


        $$scope.rzlcStepEntity.processInstanceId = $CertusJsonAjax.getProInstanceId();
        $$scope.rzlcStepEntity.stepInstanceId = $CertusJsonAjax.getStepInstanceId();

        $$scope.companySelect = [
            {name: "赛特斯集团", code: "STSJT"},
        ]

        $$scope.belongCompanyCodeSelect = [
            {name:"赛特斯广东",code:"STSGD"},
            {name:"赛特斯南京",code:"STSNJ"},
            {name:"赛特斯北京",code:"STSBJ"},
            {name:"赛特斯上海",code:"STSSH"},
            {name:"融合运维事业部",code:"SYB-RX"},
            {name:"浩方科技",code:"HFKJ"},
            {name:"浩方信息",code:"HFXX"}
        ]

        $$scope.userNumberSelect = [
            {name: "9", code: "9"},
            {name: "3", code: "3"},
            {name: "HK", code: "HK"},
            {name: "HX", code: "HX"}
        ]
        if ($$scope.rzlcStepEntity.baseUser.belongCompanyCode == "HFXX") {
            $$scope.userNumberSelect = [
                {name: "HX", code: "HX"}
            ]
            $$scope.unsHead = "HX";
            $CertusFormAjax.ajax("nextHeadFunc", {nowStart: "HX"}, function (res) {
                //放入 現在 的
                $$scope.nextUserIdSelect = res.data;
            })
        } else if ($$scope.rzlcStepEntity.baseUser.belongCompanyCode == "HFKJ") {

            $$scope.userNumberSelect = [
                {name: "HK", code: "HK"}
            ]
            $$scope.unsHead = "HK";
            $CertusFormAjax.ajax("nextHeadFunc", {nowStart: "HK"}, function (res) {
                //放入 現在 的
                $$scope.nextUserIdSelect = res.data;
            })
        } else {
            $$scope.userNumberSelect = [
                {name: "9", code: "9"},
                {name: "3", code: "3"},
                {name:"10",code:"10"}
            ]

        }

        for (var cs in $$scope.companySelect) {
            if ($$scope.companySelect[cs].code == $$scope.rzlcStepEntity.baseUser.belongCompanyCode) {
                $$scope.rzlcStepEntity.baseUser.departmentUser.companyName = $$scope.companySelect[cs].name;
            }
        }
    }
});


$$scope.getSex = function (a) {
    if (a == 1) {
        return "男";
    } else {
        return "女";
    }
}

$$scope.getMarriage = function(a){
    if(a == 1){
        return "已婚";
    }else if(a == 0 ){
        return "未婚";
    }else if(a == 2){
        return "已婚已育";
    }

    return "未婚";
}

$$scope.unsHeadFunc = function (a) {
    $CertusFormAjax.ajax("nextHeadFunc", {nowStart: a}, function (res) {
        //放入 現在 的
        $$scope.nextUserIdSelect = res.data;
    })
}


//根據 工號 選擇


$$scope.infoSubmitEnd = function () {
    if(certusValidateNotnull()){
        if(!$$scope.rzlcStepEntity.baseUser.enrollTime){
            layer.msg("请填入入职时间")
            return;
        }
        $CertusJsonAjax.ajax("infoSubmitEnd", $$scope.rzlcStepEntity, function (res) {
            if (res.data == "success") {
                // findBacklogPerson($CertusFormAjax,$CertusJsonAjax.getStepInstanceId());
                // history.back();
                location.href = "#/addUserList";
                return;
            }
            layer.msg(res.data);
        })
    }
}

$$scope.noEntry = function () {
    layer.confirm('确认员工不会入职？', {
        title: '提示信息',
        btn: ["确定", '取消'] //按钮
    }, function () {
        $CertusJsonAjax.ajax("noEntry", $$scope.rzlcStepEntity, function (res) {
            if (res.data == "success") {
                // findBacklogPerson($CertusFormAjax,$CertusJsonAjax.getStepInstanceId());
                // history.back();
                location.href = "#/addUserList";
                layer.closeAll();
                return;
            }
            layer.msg("數據錯誤");
        })
    });

}
